﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;

[assembly: WebResource("CrmControls.MyJsFile.js", "text/javascript")]
namespace CrmControls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:CrmTextBox1 runat=server></{0}:CrmTextBox1>")]
    public class CrmTextBox : System.Web.UI.WebControls.TextBox
    {
        protected override void Render(HtmlTextWriter writer)
        {
            if (KontrolTipi == Tip.Sayi)
                this.Attributes.Add("onkeydown", "SayiKontrol()");
            else if (KontrolTipi == Tip.Harf)
                this.Attributes.Add("onkeydown", "HarfKontrol()");
            if (BuyukHarf == HarfBoyut.BuyukHarf)
                this.Attributes.Add("onkeyup", "BuyukHarf('" + this.ID + "')");
            else if (BuyukHarf == HarfBoyut.KucukHarf)
                this.Attributes.Add("onkeyup", "KucukHarf('" + this.ID + "')");
            if (NullKontrol == true)
                this.Attributes.Add("onblur", "NullControl('" + this.ID + "')");
            else
                NullKontrol = false;
            if (NoktaKontrol == true)
                this.Attributes.Add("onkeyup", "addCommas('" + this.ID + "')");
            // this.Attributes.Add("onkeydown", "EnterTab('" + this.ID + "');");
            base.Render(writer);
        }
        private int minlenght;
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public int MinLenght
        {
            get { return minlenght; }
            set { minlenght = value; }
        }

        private int maxlength;
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public int Maxlength
        {
            get { return maxlength; }
            set { maxlength = value; }
        }

        private Tip TipControl;

        private bool noktaKontrol;
        
        public bool NoktaKontrol
        {
            get { return noktaKontrol; }
            set { noktaKontrol = value; }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public Tip KontrolTipi
        {
            get { return TipControl; }
            set { TipControl = value; }
        }

        private HarfBoyut buyukHarf;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public HarfBoyut BuyukHarf
        {
            get { return buyukHarf; }
            set { buyukHarf = value; }
        }

        private bool nullKontrol;
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public bool NullKontrol
        {
            get { return nullKontrol; }
            set { nullKontrol = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (Maxlength > 0)
            {
                this.Attributes.Add("onkeypress", "LimitInput(this)");
                this.Attributes.Add("onbeforepaste", "doBeforePaste(this)");
                this.Attributes.Add("onpaste", "doPaste(this)");
                this.Attributes.Add("onmousemove", "LimitInput(this)");
                this.Attributes.Add("maxLength", this.Maxlength.ToString());
            }
            string jsResource = "CrmControls.MyJsFile.js";
            this.Page.ClientScript.RegisterClientScriptResource(this.GetType(), jsResource);
            base.OnPreRender(e);
        }

        public enum Tip
        {
            Sayi,
            Harf,
            Multi
        }

        public enum HarfBoyut
        {
            BuyukHarf,
            KucukHarf,
            Multi
        }
    }

}
